package com.eduask.action;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.eduask.beans.CarSchema;
import com.eduask.service.CarSchemaService;

@Scope(value = "prototype")
@Controller
public class CarSchenaAction {
	
	@Autowired
	private CarSchemaService carSchemaService;
	
	@RequestMapping("/bookTicket")
	public String bookTicket() {
		return "bookTicket";
	}
	
	@RequestMapping("/leaveMessage")
	public String leaveMessage() {
		return "leaveMessage";
	}
	
	@RequestMapping("/leaveMessageSuccess")
	public String leaveMessageSuccess() {
		return "leaveMessageSuccess";
	}
	
	@RequestMapping("/logFaild")
	public String logFaild() {
		return "logFaild";
	}
	
	@RequestMapping("/logSuccess")
	public String logSuccess() {
		return "logSuccess";
	}
	
	@RequestMapping("/lookMessage")
	public String lookMessage() {
		return "lookMessage";
	}
	
	@RequestMapping("/normalUserlogSuccess")
	public String normalUserlogSuccess() {
		return "normalUserlogSuccess";
	}
	
	@RequestMapping("/pleaseLogin")
	public String pleaseLogin() {
		return "pleaseLogin";
	}
	
	@RequestMapping("/getStartplace")
	public List<String> getStartplace(Map<String,List<String>> map) {
		List<String> startplace = carSchemaService.getStartplace();
		map.put("startplace",startplace);
		return startplace;
	}
	
	@ResponseBody
	@RequestMapping("/getEndplace")
	public List<String> getEndplace(String startPlace) {
		
		List<String> startplace = carSchemaService.getEndplace(startPlace);
		
		System.out.println(startplace);
		
		return startplace;
	}
	@ResponseBody
	@RequestMapping("/getAllcarOrder")
	public List<CarSchema> getAllcarOrder(String start,String endplace,String time) {
		System.out.println("start:"+start + "endplace:"+ endplace + "time:"+ time);
		List<CarSchema> carlist = carSchemaService.getCar(start, endplace,time);
		System.out.println("carList:"+carlist);
		return carlist;
	}
	
	
	@RequestMapping("/ticketLook")
	public String  ticketLook(Map<String,List<String>> map) {
		
		List<String> startplace = carSchemaService.getStartplace();
		
		map.put("startplace",startplace);
		
		return "ticketLook";
	}
	
	@RequestMapping("/showSaledTicket")
	public String showSaledTicket() {
		return "showSaledTicket";
	}
	
	@RequestMapping("/tuiPiao")
	public String tuiPiao() {
		return "tuiPiao";
	}
	
	@RequestMapping("/tuiPiaoSuccess")
	public String tuiPiaoSuccess() {
		return "tuiPiaoSuccess";
	}
	
	@RequestMapping("/updateZhuCe")
	public String updateZhuCe() {
		return "updateZhuCe";
	}
	
	@RequestMapping("/updateUserSuccess")
	public String updateUserSuccess() {
		return "updateUserSuccess";
	}
	
	@RequestMapping("/userManage")
	public String userManage() {
		return "userManage";
	}
	
	@RequestMapping("/userManagerFaild")
	public String userManagerFaild() {
		return "userManagerFaild";
	}
	
	@RequestMapping("/zhuche")
	public String zhuche() {
		return "zhuche";
	}
	
	@RequestMapping("/zhucheSuccess")
	public String zhucheSuccess() {
		return "zhucheSuccess";
	}
	
	/*@RequestMapping("/ticketLook")
	public String ticketLook(CarSchema carSchema, Map<String, Object> map) {
		map.put("list", carSchemaService.findCarSchemas(carSchema));
		return "ticketLook";
	}*/
	 @InitBinder
	 public void initBinder(WebDataBinder binder){
	        binder.registerCustomEditor(Date.class,new CustomDateEditor(
	                new SimpleDateFormat("yyyy-MM-dd HH:ss:mm"),true));

	    }
	
}
